﻿using IterationLife.Domains.Sports.Models;
using Util;
using Util.Maps;

namespace IterationLife.Football.MTSports.Dtos.Sports {
    /// <summary>
    /// 运动员数据传输对象扩展
    /// </summary>
    public static class SportAthleteDtoExtension {
        /// <summary>
        /// 转换为运动员实体
        /// </summary>
        /// <param name="dto">运动员数据传输对象</param>
        public static SportAthlete ToEntity( this SportAthleteDto dto ) {
            if ( dto == null )
                return new SportAthlete();
            return dto.MapTo( new SportAthlete( dto.Id.ToGuid() ) );
        }
        
        /// <summary>
        /// 转换为运动员实体
        /// </summary>
        /// <param name="dto">运动员数据传输对象</param>
        public static SportAthlete ToEntity2( this SportAthleteDto dto ) {
            if( dto == null )
                return new SportAthlete();
            return new SportAthlete( dto.Id.ToGuid() ) {
                PartnerAthleteId = dto.PartnerAthleteId,
                IdCard = dto.IdCard,
                Name = dto.Name,
                Nationality = dto.Nationality,
                Sex = dto.Sex,
                Birthday = dto.Birthday,
                Stature = dto.Stature,
                Weight = dto.Weight,
                HistoryAverageJsonData = dto.HistoryAverageJsonData,
                CreationTime = dto.CreationTime,
                CreatorId = dto.CreatorId,
                LastModificationTime = dto.LastModificationTime,
                LastModifierId = dto.LastModifierId,
                IsDeleted = dto.IsDeleted,
                Version = dto.Version,
            };
        }
        
        
        /// <summary>
        /// 转换为运动员数据传输对象
        /// </summary>
        /// <param name="entity">运动员实体</param>
        public static SportAthleteDto ToDto(this SportAthlete entity) {
            if( entity == null )
                return new SportAthleteDto();
            return entity.MapTo(new SportAthleteDto());
        }

        /// <summary>
        /// 转换为运动员数据传输对象
        /// </summary>
        /// <param name="entity">运动员实体</param>
        public static SportAthleteDto ToDto2( this SportAthlete entity ) {
            if( entity == null )
                return new SportAthleteDto();
            return new SportAthleteDto {
                Id = entity.Id.ToString(),
                PartnerAthleteId = entity.PartnerAthleteId,
                IdCard = entity.IdCard,
                Name = entity.Name,
                Nationality = entity.Nationality,
                Sex = entity.Sex,
                Birthday = entity.Birthday,
                Stature = entity.Stature,
                Weight = entity.Weight,
                HistoryAverageJsonData = entity.HistoryAverageJsonData,
                CreationTime = entity.CreationTime,
                CreatorId = entity.CreatorId,
                LastModificationTime = entity.LastModificationTime,
                LastModifierId = entity.LastModifierId,
                IsDeleted = entity.IsDeleted,
                Version = entity.Version,
            };
        }
    }
}
